package com.kawa.kemanage.controller.app;


import com.kawa.kemanage.service.FavoritesService;
import com.kawa.kemanage.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: KAIyo
 * @Date: 2025/6/27 17:08
 * @Version: v1.0.0
 * @Description: 收藏功能控制器
 **/
@RestController
@RequestMapping("/app/favorites")
@CrossOrigin
public class FavoritesController {

    @Autowired
    private FavoritesService favoritesService;

    /**
     * 添加收藏
     */
    @PostMapping("/add/{userId}/{contentId}")
    public Result addFavorite(@PathVariable Long userId, @PathVariable Long contentId) {
        return Result.success(favoritesService.addFavorite(userId, contentId));
    }

    /**
     * 取消收藏
     */
    @PostMapping("/cancel/{userId}/{contentId}")
    public Result cancelFavorite(@PathVariable Long userId, @PathVariable Long contentId) {
        return favoritesService.cancelFavorite(userId, contentId);
    }

    /**
     * 获取用户收藏列表
     */
    @GetMapping("/list")
    public Result getFavoritesList(@RequestParam Long userId) {
        return favoritesService.getFavoritesList(userId);
    }

    /**
     * 检查是否已收藏
     */
    @GetMapping("/check/{userId}/{contentId}")
    public Result checkFavorite(@PathVariable Long userId, @PathVariable Long contentId) {
        return favoritesService.checkFavorite(userId, contentId);
    }
}
